package week10;

import java.awt.Graphics;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Color;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;


public class WZQFrame extends JPanel implements WzqCfg{
    //定义画笔
    public Graphics gpaint;
    //初始化界面
    public void initUI(){
        //初始化界面、设置标题
        JFrame boardFrame = new JFrame();
        boardFrame.setTitle("WZQ");
        boardFrame.setSize(800, 600);//设置窗体大小
        boardFrame.setLocationRelativeTo(null);//创意初始化位置
        boardFrame.setDefaultCloseOperation(3);//窗体的关闭方式
        //界面的布局方式
        boardFrame.setLayout(new BorderLayout());
        boardFrame.add(this);
        JPanel eastp = new JPanel();//设置一个右侧的按钮区
        eastp.setPreferredSize(new Dimension(100,0));//设置按钮组件区宽度
        // 定义控件
        JButton btnStart = new JButton("开始游戏");
        btnStart.setPreferredSize(new Dimension(90,40));
        JButton btnLose = new JButton("认输");
        btnLose.setPreferredSize(new Dimension(90,40));
        String[] itmArr = {"双人对战","人机对战"};
        JComboBox<String> cbItem = new JComboBox<String>(itmArr);
        cbItem.setPreferredSize(new Dimension(90,40));
        //把控件安装到JPanel上
        eastp.add(btnStart);
        eastp.add(btnLose);
        eastp.add(cbItem);
        // 把JPanel加到窗体上
        boardFrame.add(eastp,BorderLayout.EAST);

        boardFrame.setVisible(true);
    }
    //画棋盘
    //重写JPanel中的paint方法
    @Override
    public void paint(Graphics g){
        super.paint(g);//先覆盖上一次的棋局
        // for(int i = 0;i<15;i++){
        //     g.drawLine(30, 30+i*35, 30+35*14, 30+i*35);//画横线
        //     g.drawLine(30+i*35, 30, 30+i*35, 30+14*35);//画竖线
        // }
        // 改进棋盘格的绘制算法
        g.setColor(Color.black);
        for(int i = 0;i<col;i++){
            g.drawLine(x, y+size*i, x+size*(col-1), y+size*i);
        }
        for(int i = 0;i<row;i++){
            g.drawLine(x+i*size, y, x+i*size, y+size*(row-1));
        }
    }
    //程序运行的主方法
    public static void main(String[] args) {
        WZQFrame board = new WZQFrame();
        board.initUI();
    }
}
